package com.dt.platform.generator.module.oa;

import com.dt.platform.constants.db.OaTables;
import com.dt.platform.constants.enums.oa.VisitStatusEnum;
import com.dt.platform.domain.oa.VisitorRecord;
import com.dt.platform.generator.config.Config;
import com.dt.platform.oa.page.VisitorRecordPageController;
import com.dt.platform.proxy.oa.VisitorRecordServiceProxy;
import com.github.foxnic.generator.builder.view.config.DatePickerType;
import com.github.foxnic.generator.config.WriteMode;

public class VisitorMgrGtr extends BaseCodeGenerator {


    public VisitorMgrGtr() {
        super(OaTables.OA_VISITOR_RECORD.$TABLE,"699537450065723398");
    }

    public void generateCode() throws Exception {
        System.out.println(this.getClass().getName());



        cfg.view().field(OaTables.OA_VISITOR_RECORD.ID).basic().hidden(true);

        cfg.view().field(OaTables.OA_VISITOR_RECORD.VISITOR_NAME).search().fuzzySearch();
        cfg.view().field(OaTables.OA_VISITOR_RECORD.VISITOR_CARD).search().fuzzySearch();
        cfg.view().field(OaTables.OA_VISITOR_RECORD.VISITOR_MOBILE).search().fuzzySearch();
        cfg.view().field(OaTables.OA_VISITOR_RECORD.USER_NAME).search().fuzzySearch();
        cfg.view().field(OaTables.OA_VISITOR_RECORD.CT).search().fuzzySearch();

        cfg.view().field(OaTables.OA_VISITOR_RECORD.VISIT_TIME).search().range();

        cfg.view().search().inputLayout(
                new Object[]{
                        OaTables.OA_VISITOR_RECORD.STATUS,
                        OaTables.OA_VISITOR_RECORD.VISITOR_NAME,
                        OaTables.OA_VISITOR_RECORD.VISITOR_CARD,
                        OaTables.OA_VISITOR_RECORD.VISITOR_MOBILE,
                },
                new Object[]{
                        OaTables.OA_VISITOR_RECORD.USER_NAME,
                        OaTables.OA_VISITOR_RECORD.VISIT_TIME
                }
        );


        cfg.view().search().labelWidth(1,Config.searchLabelWidth);
        cfg.view().search().labelWidth(2,Config.searchLabelWidth);
        cfg.view().search().labelWidth(3,Config.searchLabelWidth);
        cfg.view().search().labelWidth(4,Config.searchLabelWidth);
        cfg.view().search().inputWidth(Config.searchInputWidth);

        cfg.view().field(OaTables.OA_VISITOR_RECORD.VISIT_TIME).form().dateInput().type(DatePickerType.datetime).defaultNow().format("yyyy-MM-dd HH:mm:ss").search().range();
        cfg.view().field(OaTables.OA_VISITOR_RECORD.LEAVE_TIME).form().dateInput().type(DatePickerType.datetime).format("yyyy-MM-dd HH:mm:ss").search().range();

        cfg.view().field(OaTables.OA_VISITOR_RECORD.STATUS).form().radioBox().enumType(VisitStatusEnum.class);

        cfg.view().field(OaTables.OA_VISITOR_RECORD.VISITOR_NAME).form().validate().required();

        cfg.view().field(OaTables.OA_VISITOR_RECORD.NOTES).form().textArea().height(150);
        cfg.view().field(OaTables.OA_VISITOR_RECORD.CT).form().textArea().height(100);

        cfg.view().field(OaTables.OA_VISITOR_RECORD.CREATE_TIME).table().disable(true);
        cfg.view().field(OaTables.OA_VISITOR_RECORD.CREATE_BY).table().disable(true);
        cfg.view().field(OaTables.OA_VISITOR_RECORD.UPDATE_BY).table().disable(true);
        cfg.view().field(OaTables.OA_VISITOR_RECORD.UPDATE_TIME).table().disable(true);
        cfg.view().field(OaTables.OA_FIN_ACCOUNTING_RECORD.OPER_TIME).table().disable(true);
        cfg.view().field(OaTables.OA_VISITOR_RECORD.NOTES).table().disable(true);

        cfg.view().formWindow().bottomSpace(100);
        cfg.view().formWindow().width(Config.baseFormWidth);

        cfg.view().form().addGroup("访问人员",
                new Object[] {
                        OaTables.OA_VISITOR_RECORD.VISITOR_NAME,
                        OaTables.OA_VISITOR_RECORD.VISITOR_MOBILE,
                },
                new Object[] {
                        OaTables.OA_VISITOR_RECORD.VISITOR_CARD,
                }
        );
        cfg.view().list().disableBatchDelete();
        cfg.view().form().addGroup("访问信息",
                new Object[] {
                        OaTables.OA_VISITOR_RECORD.USER_NAME,
                }
        );
        cfg.view().form().addGroup(null,
                new Object[] {
                        OaTables.OA_VISITOR_RECORD.VISIT_TIME,
                },
                new Object[] {
                        OaTables.OA_VISITOR_RECORD.LEAVE_TIME,
                }
        );
        cfg.view().form().addGroup(null,
                new Object[] {
                        OaTables.OA_VISITOR_RECORD.CT,
                 }
        );

        cfg.view().form().addGroup(null,
                new Object[] {
                        OaTables.OA_VISITOR_RECORD.NOTES,
                }
        );
        cfg.view().list().operationColumn().addActionButton("签到","sign","sign-button");
        cfg.view().list().operationColumn().addActionButton("离开","leave","leave-button");


        //文件生成覆盖模式
        cfg.overrides()
                .setServiceIntfAnfImpl(WriteMode.IGNORE) //服务与接口
                .setControllerAndAgent(WriteMode.IGNORE) //Rest
                .setPageController(WriteMode.IGNORE) //页面控制器
                .setFormPage(WriteMode.COVER_EXISTS_FILE) //表单HTML页
                .setListPage(WriteMode.COVER_EXISTS_FILE)
                .setExtendJsFile(WriteMode.IGNORE); //列表HTML页
        //列表HTML页
        //生成代码
        cfg.buildAll();
    }

    public static void main(String[] args) throws Exception {
        VisitorMgrGtr g=new VisitorMgrGtr();
        //生成代码
        g.generateCode();

        //移除之前生成的菜单，视情况执行
//        g.removeByBatchId("471622036347682816");
        //生成菜单
        //
     // g.generateMenu(VisitorRecordServiceProxy.class, VisitorRecordPageController.class);
    }

}
